﻿using DailyApp.WPF.DTOs;
using DailyApp.WPF.Service;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace DailyApp.WPF.ViewModels.Dialogs
{
    /// <summary>
    /// 添加待办事项
    /// </summary>
    internal class AddWaitUCViewModel :  IDialogHostAware
    {
        public AddWaitUCViewModel()
        {
            SaveCommand=new DelegateCommand(Save);
            CancelCommand=new DelegateCommand(Cancel);
        }
        /// <summary>
        /// 确定命令
        /// </summary>
        public DelegateCommand SaveCommand { get; set; }

        /// <summary>
        /// 取消命令
        /// </summary>
        public DelegateCommand CancelCommand { get; set; }



        /// <summary>
        /// 打开过程执行
        /// </summary>
        /// <param name="parameters"></param>
        public void OnDialogOpening(IDialogParameters parameters)
        {

        }
        /// <summary>
        /// 确定方法
        /// </summary>
        private void Save()
        {
            if (string.IsNullOrEmpty(WaitInfoDTO.Badge)|| string.IsNullOrEmpty(WaitInfoDTO.Name))
            {
                MessageBox.Show("待办事项信息不全"); return;
            }
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogParameters pairs = new DialogParameters();
                pairs.Add("AddWaitInfo", WaitInfoDTO);
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.OK,pairs));
            }
        }
        /// <summary>
        /// 待办事项信息
        /// </summary>
        public WaitInfoDTO WaitInfoDTO { get; set; }=new WaitInfoDTO();

        /// <summary>
        /// 取消方法
        /// </summary>
        private void Cancel()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogHost.Close(DialogHostName,new DialogResult(ButtonResult.No));
            }
        }
        /// <summary>
        /// 对话框主机唯一标识
        /// </summary>
        private const string DialogHostName = "RootDialog";
    }
}
